package com.otherTest.designpattern.creationalpattern.singleton.dcl;


/**
 * @Description: 双重检查锁单例模式
 * 懒加载，线程安全，实现较复杂
 * 这种方式采用双锁机制，安全且在多线程情况下能保持高性能
 * @author: conceit
 * @Date: 2018/8/29 16:31
 */
public class SingleDoubleCheckLockBaseObject {

    /**
     * @Description: volatile保证了不同线程对这个变量进行操作时的可见性
     */
    private volatile static SingleDoubleCheckLockBaseObject singleDoubleCheckLockBaseObject;

    /**
     * @Description: 私有化构造方法
     */
    private  SingleDoubleCheckLockBaseObject(){}


    /**
     * @Description: 核心方法
     */
    public static SingleDoubleCheckLockBaseObject getInstance(){
       if(null==singleDoubleCheckLockBaseObject){
            synchronized (SingleDoubleCheckLockBaseObject.class){
                if(null==singleDoubleCheckLockBaseObject){
                    singleDoubleCheckLockBaseObject =new SingleDoubleCheckLockBaseObject();
                }
            }
       }
       return singleDoubleCheckLockBaseObject;
    }
    /**
     *测试方法
     */
    public void showMessage(){
        System.out.println(this.getClass().getName()+"--->this is showMessage");
    }
}
